// pages/set/set.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shop_content_list:[],
    showTopTips:false,
    info:"",
    user_phone:'',
    formData:{},
    value: -1
  },

    shop_details_commit:function(e){
      let that = this
      var shop_name = e.detail.value.shop_name,
      shop_people = e.detail.value.shop_people,
      shop_address = e.detail.value.shop_address,
      contact_phone = e.detail.value.contact_phone
      if(contact_phone == ""){
        app.showTopTips("联系电话不能为空", this)
      } else if (!(/^1(3|4|5|7|8)\d{9}$/.test(contact_phone))){
        app.showTopTips("电话号码有误，请重新填写", this)
      }else if (shop_name == "") {
        app.showTopTips("店铺名称不能为空", this)
      } else if (shop_people == "") {
        app.showTopTips("负责人不能为空", this)
      } else if (shop_address == "") {
        app.showTopTips("门店地址不能为空", this)
      }else{
          app.ajax({
              url: app.host + 'mall/User/shop_details_commit',
              data: {
                shop_name: shop_name,
                shop_people: shop_people,
                shop_address: shop_address,
                contact_phone: contact_phone,
                cate_id: that.data.formData.sc_id
              },
              success: function (res) {
                  
                  wx.showToast({
                      title: res.data.msg,
                      icon: 'success',
                      duration: 1000
                  })
                  setTimeout(function () {
                    wx.navigateBack()
                  }, 1000)
              }
          });
      } 
        
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.showLoading({
      title: '加载中'
    })
    app.ajax({
      url: app.host + 'mall/user/shop_details_commit',
      success:function(res){
        wx.hideLoading()
        let formData = res.data.data
        let value = -1
        for (let i in formData.cate){
          if (formData.cate[i].sc_id == formData.sc_id){
            value = i
          }
        }
        that.setData({
          formData:res.data.data,
          value: value
        })
        console.log(res.data.data)
      }
    })
  },
  choose_shop:function(e){
    let value = e.detail.value
    let formData = this.data.formData
    let cate = formData.cate
    formData.sc_id = cate[value].sc_id
    console.log(formData)
    this.setData({
      formData: formData,
      value: value
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})